Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Add Name and FileName to IFormFile #500

Merged
merged 1 commit into from
Dec 4, 2015
Merged

Conversation

khellang
Copy link
Contributor

@khellang khellang commented Dec 4, 2015

Fixes #499. These names should probably be cached somewhere. Anyone opposed to exposing a Name property on IFormFile backed by a Lazy<string>?

@davidfowl
Copy link
Member

This isn't how I think it should be done. We should update FormFile to have a name property on it. Make it lazy there.

@khellang
Copy link
Contributor Author

khellang commented Dec 4, 2015

@davidfowl Hence my "These names should probably be cached somewhere. Anyone opposed to exposing a Name property on IFormFile backed by a Lazy<string>?" 😉

@davidfowl
Copy link
Member

@khellang Lazy is overkill, it doesn't need to be thread safe. Also add a test for this once you're done.

@khellang
Copy link
Contributor Author

khellang commented Dec 4, 2015

Lazy is overkill, it doesn't need to be thread safe.

So are you saying parse the name eagerly? Or just _name ?? (_name = GetName())?

@davidfowl
Copy link
Member

Lazy is fine but using Lazy<T> is just overhead since we don't care about thread safety.

@khellang
Copy link
Contributor Author

khellang commented Dec 4, 2015

@davidfowl How does it look now?

@@ -149,7 +149,9 @@ public Task<IFormCollection> ReadFormAsync(CancellationToken cancellationToken)
// Find the end
await section.Body.DrainAsync(cancellationToken);

var file = new FormFile(_request.Body, section.BaseStreamOffset.Value, section.Body.Length)
var name = HeaderUtilities.RemoveQuotes(contentDisposition.Name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can name ever be null here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems not

@davidfowl
Copy link
Member

Much better!

@khellang
Copy link
Contributor Author

khellang commented Dec 4, 2015

What about FileName as well?

@davidfowl
Copy link
Member

Go for it

@davidfowl
Copy link
Member

I think I change my mind on the lazy. Not worth it. Parse it out and just assign eagerly.

@khellang
Copy link
Contributor Author

khellang commented Dec 4, 2015

Have you looked at the getters for Name and FileName in CDHV? Granted, it's not often you send files, and not very many of them, so it probably won't matter much.

Want me to strip off that last commit then? 😄

@khellang khellang changed the title Expose GetName extension on IFormFile Add Name and FileName to IFormFile Dec 4, 2015
@khellang khellang force-pushed the form-file-name branch 2 times, most recently from 7a3310e to f8bb6f6 Compare December 4, 2015 12:12
@khellang
Copy link
Contributor Author

khellang commented Dec 4, 2015

Added dfca389 to close #352 as well.


public FormFile(Stream baseStream, long baseStreamOffset, long length)
public FormFile(Stream baseStream, long baseStreamOffset, long length, ContentDispositionHeaderValue contentDisposition)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move the quote removal on to the outside and just pass the name and file name. It's weird to have the header dependency in here (always was)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

return HeaderUtilities.RemoveQuotes(cd?.Name);
foreach (var file in this)
{
if (string.Equals(name, file.Name))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordinal or ignore case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I just kept what was already there. What would you expect?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OrdinalIgnoreCase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@davidfowl
Copy link
Member

Ok this PR is good to go once the CI passes. Then we'll have to see what repos break. If I had to guess. MVC would be broken

This commits also gets rid of the name
closure in FormFileCollection by interating
over the files in the collection instead
of using Find and FindAll.

Closes aspnet#352 and aspnet#499
davidfowl added a commit that referenced this pull request Dec 4, 2015
Add Name and FileName to IFormFile
@davidfowl davidfowl merged commit dfe2d41 into aspnet:dev Dec 4, 2015
@khellang khellang deleted the form-file-name branch December 4, 2015 20:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants